package com.hbt.springbootquick;

import com.hbt.springbootquick.conf.MyMvcConfig;
import com.hbt.springbootquick.dao.UserDao;
import com.hbt.springbootquick.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Controller
public class asd {

    @Autowired
    UserDao userDao;

    @Autowired
    MyMvcConfig mvcConfig;


    @RequestMapping("ex")
    @ResponseBody
    public String asda (@RequestParam("file") MultipartFile file) {
//        try {
//            int i = 4/0;
//        }catch (Exception e){
//            System.out.println("补获到异常");
//        }
        File f = new File("c:/Users/AS/Desktop/2.jpg");
        try {
            file.transferTo(f);
        } catch (IOException e) {
            System.out.println("ex*************");
        }
        System.out.println("dsfsdfd");
        return "123";
    }

    @RequestMapping("yml")
    @ResponseBody
    public String asdw(){
        System.out.println(mvcConfig.getPath1());
        return mvcConfig.getPath();
    }

    @RequestMapping("upload")
    @ResponseBody
    public String asdf(@RequestParam("file") MultipartFile file){
        File f = new File("c:/Users/ASUS/Desktop/2.jpg");
        try {
            file.transferTo(f);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "upload";
    }

    @RequestMapping("index")
    public String sfh(){
        return "index1";
    }


    @RequestMapping("dao")
    @ResponseBody
    public String vdtg(){
//        List<User> users = userDao.getAllUsers();
//        for(User user: users){
//            System.out.println(user);
//        }
        List<User> users = userDao.getUserByUsername("999");
        System.out.println(users.get(0));
        return "asddsfer";
    }

    @RequestMapping("abc")
    public String pasdfd(Map<String, Object> map){
        User user = new User();
        user.setUsername("asfsd");
        user.setAge(124);
        user.setPassword("dasfsdf21");
        map.put("user", user);
        map.put("list", Arrays.asList("sdfdsf", "sdfsf", "sdgdfg"));
        return "1";
    }
    @RequestMapping("aaa")
    @ResponseBody
    public String dfds(@RequestParam("id") String id, @RequestParam("name") String name){

        return id+name;
    }
}
